unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADODataSet1: TADODataSet;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  I:Integer;
  SQLA:string;
  StrsA:TStringList;
  StrsB:TStringList;
  FieldName:string;
  FieldValx:string;
begin
  SQLA:='SELECT * FROM  TBL_CARD WHERE UNIT_LINK=%S AND CARD_IDEX=%D ';
  SQLA:=Format(SQLA,[QuotedStr('0001-0001'),3864]);

  ADODataSet1.CommandText:=SQLA;
  ADODataSet1.Open;

  ShowMessageFmt('%D',[ADODataSet1.RecordCount]);

  StrsA:=TStringList.Create;
  StrsB:=TStringList.Create;

  for I:=0 to ADODataSet1.FieldDefs.Count-1 do
  begin
    StrsA.Clear;
    
    FieldName:=ADODataSet1.FieldDefs.Items[I].Name;
    
    ADODataSet1.First;
    while not ADODataSet1.Eof do
    begin
      FieldValx:=ADODataSet1.FieldByName(FieldName).AsString;

      if StrsA.IndexOf(FieldValx)=-1 then
      begin
        StrsA.Add(FieldValx);
      end;  
      ADODataSet1.Next;
    end;

    if StrsA.Count>1 then
    begin
      StrsB.Add(FieldName);
    end;
  end;

  ShowMessage(StrsB.Text);


  FreeAndNil(StrsA);
  FreeAndNil(StrsB);
end;

end.
